package pl.edu.mimuw.irs.rcp.view.roles;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Collection;

import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.Viewer;

import pl.edu.mimuw.irs.core.model.design.resource.Role;

public class RolesViewContentProvider implements IStructuredContentProvider, PropertyChangeListener {

	// *** Attributes
	
	private final Viewer viewer;
	
	// *** Constructors

	public RolesViewContentProvider(Viewer viewer) {
		this.viewer = viewer;
	}
	
	// *** Methods

	@SuppressWarnings("unchecked")
	@Override
	public Object[] getElements(Object inputElement) {
		if (inputElement != null) {
			Collection<Role> content = (Collection<Role>)inputElement;
			return content.toArray();
		} else {
			return new Object[0];
		}
	}

	@Override
	public void dispose() {

	}

	@Override
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
		// XXX inputChanged - chyba zbędne
	}

	@Override
	public void propertyChange(PropertyChangeEvent arg0) {
		viewer.refresh();
	}
}
